//
//  ViewController.swift
//  SandboxSwiftDemo2
//
//  Created by 李煜 on 2024/4/20.
//

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        /**
         --------------------------------------------------------
         上面形式获取路径返回值为 String 形式，下面形式返回值为 URL 形式
         可根据实际情况选择合适的方式
         --------------------------------------------------------
         */

        let dataURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("sqliteName").appendingPathExtension("sqlite")

        /// AppGroup目录路径
        let appGroupIdentifier = "group.com.star.LTXiOSUtils.extension"
        let groupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier)

        //
        store()
    }
}

extension ViewController {
    func store() {
        // 数据存取
        
        let dicPathURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("dic3.plist")

//        ios16            .appending(path: "dic.plist", directoryHint: .notDirectory))!
        let dic: [String: Any] = ["name": "张三", "age": 24]
        // 写入
        //方法1
//        NSDictionary(dictionary: dic).write(to: dicPathURL, atomically: true)
        //方法2
//        true if the current process has write privileges for the file at path; otherwise false if the process does not have write privileges or the existence of the file could not be determined.
//        if FileManager.default.isWritableFile(atPath: dicPathURL.absoluteString) {
//            debugPrint("写入成功")
//        }
    }
}
